import com.cs.core.enums.DriverType
import com.cs.core.enums.NameType
import com.cs.core.factory.GenFactory
import com.cs.core.model.JdbcModel
import com.cs.core.model.NameModel

def code(def tplDir, def outDir) {
    final JdbcModel jdbcProp = new JdbcModel()
    jdbcProp.setDriver(DriverType.MYSQL8.getType())
    jdbcProp.setJdbcUrl("jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull")
    jdbcProp.setUser("root")
    jdbcProp.setPassword("123456")

    GenFactory genFactory = GenFactory.newBuilder().source(jdbcProp).out(tplDir, outDir)
            .parent("com.cs.web")
            .author("wind")
            .template("ftl/mybatis-plus/extend.ftl",
                    NameModel.newBuilder()
                            .module("entity.extend")
                            .suffix("Extend")
                            .nameType(NameType.UPPER_CAMEL).build()
            )
            .template("ftl/mybatis-plus/entity.ftl",
                    NameModel.newBuilder()
                            .module("entity")
                            .suffix("")
                            .nameType(NameType.UPPER_CAMEL).build()
            )
			.template("ftl/mybatis-plus/controller.ftl",
					NameModel.newBuilder()
							.nameType(NameType.UPPER_CAMEL)
							.module("controller")
							.suffix("Controller")
							.build()
			)
			.template("ftl/mybatis-plus/mapper.ftl",
					NameModel.newBuilder()
							.nameType(NameType.UPPER_CAMEL)
							.module("mapper")
							.suffix("Mapper")
							.build()
			)
			.template("ftl/mybatis-plus/service.ftl",
					NameModel.newBuilder()
							.nameType(NameType.UPPER_CAMEL)
							.module("service")
							.suffix("Service")
							.prefix("I")
							.build()
			)
			.template("ftl/mybatis-plus/impl.ftl",
					NameModel.newBuilder()
							.nameType(NameType.UPPER_CAMEL)
							.module("service.impl")
							.suffix("ServiceImpl")
							.build()
			)
            .build()
	// 清空代码生成目录
    count = genFactory.execute(true)
	tableCount = genFactory.getTableCount()
	tplCount = genFactory.getTplCount()
	System.out.printf("=================tables:%d,template:%d,success:%d====================\n", tableCount, tplCount, count)
}
